package org.hypnus.e.engine.registry;

import org.hypnus.e.engine.handler.Handler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JdkRegistry implements Registry {
	
	private Logger logger = LoggerFactory.getLogger(JdkRegistry.class) ;
	

	@Override
	public void register(String key, Handler handler) {
		if(dataMap.putIfAbsent(key, handler)!=null){
			throw new IllegalArgumentException("key already exists! ==>"+key);
		}
	}

	@Override
	public void unRegister(String key) {
		if(dataMap.remove(key)==null){
			logger.info(" do not exists key.==>"+key) ;
		}

	}

	@Override
	public Handler lookup(String key) {
		Handler handler = dataMap.get(key) ;
		if(handler==null){
			throw new IllegalArgumentException(" can not find the key.==>"+key) ;
		}
		return handler;
	}

	@Override
	public boolean exists(String key) {
		return dataMap.containsKey(key);
	}

}
